{template '_header'}
<form action="./cashier.php" method="get" class="form-horizontal" style="margin-top:20px;">

    <div class="panel panel-default panel-class">
        <div class="panel-heading">
            销售统计 <br/>按年、月、日统计商城交易额、交易量
        </div>

        <div class="panel-body">

            <input type="hidden" name="i" value="{$_W['uniacid']}"/>
            <input type="hidden" name="r" value="statistics"/>
            <div class="page-toolbar row m-b-sm m-t-sm">


                <div class="col-sm-12">
                    <select name="year" class='form-control input-sm select-sm'>
                        {loop $years $y}
                        <option value="{$y['data']}" {if $y['selected']}selected="selected"{/if}>{$y['data']}年</option>
                        {/loop}
                    </select>
                    <select name="month" class='form-control input-sm select-sm'>
                        <option value=''>月份</option>
                        {loop $months $m}
                        <option value="{$m['data']}" {if $m['selected']}selected="selected"{/if}>{$m['data']}月</option>
                        {/loop}
                    </select>
                    <select name="day" class='form-control input-sm select-sm'>
                        <option value=''>日期</option>
                    </select>

                    <select name="type" class='form-control input-sm select-sm'>
                        <option value='0' {if $_GPC['type']==0}selected="selected"{/if}>交易额</option>
                        <option value='1' {if $_GPC['type']==1}selected="selected"{/if}>交易量</option>

                    </select>


                    <div class='btn-group btn-group-sm'>

                        <button class="btn btn-sm" type="submit"> 搜索</button>

                        {ifp 'statistics.sale.export'}
                        <button type="submit" name="export" value='1' class="btn btn-sm">导出 Excel</button>
                        {/if}
                    </div>


                </div>
            </div>

        </div>

        <div class="panel-heading">
            {if empty($type)}交易额{else}交易量{/if}：<span style="color:red; ">{$totalcount}</span>，
            最高{if empty($type)}交易额{else}交易量{/if}：<span style="color:red; ">{$maxcount}</span> {if !empty($maxcount_date)}<span>({$maxcount_date}</span>){/if}
        </div>
        <div class="panel-body">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th style='width:100px;'>
                        {if empty($_GPC['month'])}月份{else}日期{/if}
                    </th>
                    <th style='width:200px;'>{if empty($type)}交易额{else}交易量{/if}</th>
                    <th>所占比例</th>
                </tr>
                </thead>
                <tbody>
                {loop $list $row}
                <tr>
                    <td>{$row['data']}</td>
                    <td>{$row['count']}</td>
                    <td>
                        <div class="progress" style='max-width:500px;'>
                            <div style="width: {$row['percent']}%;" class="progress-bar progress-bar-info"><span
                                    style="color:#000">{php echo empty($row['percent'])?'':$row['percent'].'%'}</span>
                            </div>
                        </div>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>
    </div>
    </div>
    </div>
</form>
<script language='javascript'>
    function get_days() {

        var year = $('select[name=year]').val();
        var month = $('select[name=month]').val();
        var day = $('select[name=day]');
        day.get(0).options.length = 0;
        if (month == '') {
            day.append("<option value=''>日期</option");
            return;
        }

        day.get(0).options.length = 0;
        day.append("<option value=''>...</option").attr('disabled', true);
        $.post("{php echo cashierUrl('statistics/days')}", {year: year, month: month}, function (days) {
            day.get(0).options.length = 0;
            day.removeAttr('disabled');
            days = parseInt(days);
            day.append("<option value=''>日期</option");
            for (var i = 1; i <= days; i++) {
                day.append("<option value='" + i + "'>" + i + "日</option");
            }
            {if !empty($day)}
            day.val({$day});
            {/if}
        })
    }
    $('select[name=month]').change(function () {
        get_days();
    })
    get_days();
</script>
{template '_footer'}
